"""
反思智能体运行状态管理
"""
from typing import Any, Dict, List, Optional, TypedDict


class AgentState(TypedDict):
    """React 智能体在执行期间的状态。"""

    # 输入输出
    input: str
    output: Optional[str]

    # 推理链
    thoughts: List[str]
    actions: List[Dict[str, Any]]
    observations: List[str]

    # 当前步骤
    current_step: int
    max_steps: int

    # 工具调用结果
    tool_results: List[Dict[str, Any]]

    # 智能体状态
    is_complete: bool
    has_error: bool
    error_message: Optional[str]

    # 元数据
    metadata: Dict[str, Any]

    # 会话和模式信息
    session_id: Optional[str]
    mode: Optional[str]


def create_initial_state(input_text: str, max_steps: int = 10) -> AgentState:
    """初始化智能体状态"""
    return AgentState(
        input=input_text,
        output=None,
        thoughts=[],
        actions=[],
        observations=[],
        current_step=0,
        max_steps=max_steps,
        tool_results=[],
        is_complete=False,
        has_error=False,
        error_message=None,
        metadata={},
        session_id=None,
        mode=None,
    )